<?php

namespace App\Api;

use PhalApi\Api;
use PhalApi\Exception\BadRequestException;
use PhpOffice\PhpWord\TemplateProcessor;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;


/**
 * 小工单接口
 * @desc 刺客信条
 */
class Xgdhumeng extends Api
{
    
    public function getRules()
    {
        return array(
            'getDdate' => array(
                "username" => array("name" => "username",   "desc" => "username"),
            ),
        );
    }

    

    /**
     * 获取当天记录
     * @desc 开启任务
     */
    public function getDdate()
    {
        // 最简单的处理方式
        header('Access-Control-Allow-Origin: *');
        header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
        header('Access-Control-Allow-Headers: *');
        
        $one_info = \PhalApi\DI()->notorm->xgd_yuangong->where('username', $this->username)->fetchOne();

        if( $one_info ){
            $zhu_info = \PhalApi\DI()->notorm->xgd_zujian->where('id', $one_info['zujian'])->fetchOne();
            
            $zu_price = $zhu_info['zu_price'];


            $res = array(
                "name" => $one_info['name'],
                "user_id" => $one_info['id'],
                "username" => $one_info['username'],
                "zujian_id" => $zhu_info['name'],
                "zu_price" => $zu_price,
                "ddate" => date("Y-m-d"),
                "get_mun" => "",
                "done_mun" => "",
                "is_ok" => "no",
                "create_time" => date("Y-m-d H:i:s"),
            );


            $where = array(
                "username" => $this->username,
                "ddate" => date("Y-m-d"),
            );

            $push_info = \PhalApi\DI()->notorm->xgd_push->where($where)->fetchOne();

            if( $push_info ){
                return $push_info;
            }
            return \PhalApi\DI()->notorm->xgd_push->insert($res);
        }
    }


}
